<template>
    <div class="app-container">
        <el-card>
            <el-form ref="formDataRef" :model="formData" label-width="180px" :rules="formRuels">
                <el-form-item label="是否启用分佣" prop="brokerageEnabled">
                    <el-switch v-model="formData.brokerageEnabled"></el-switch>
                </el-form-item>
                <el-form-item label="分佣模式" prop="brokerageEnabledCondition">
                    <el-radio-group v-model="formData.brokerageEnabledCondition">
                        <el-radio :label="1">人人分销</el-radio>
                        <el-radio :label="2">指定分销</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="分销关系绑定模式" prop="brokerageBindMode">
                    <el-radio-group v-model="formData.brokerageBindMode">
                        <el-radio :label="1">首次绑定</el-radio>
                        <el-radio :label="2">注册绑定</el-radio>
                        <el-radio :label="3">覆盖绑定</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="成为推广员条件" prop="brokerageUserCondition">
                    <el-radio-group v-model="formData.brokerageUserCondition">
                        <el-radio :label="1">注册成功后</el-radio>
                        <el-radio :label="2">税务查询成功后</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="用户提现最低金额" prop="brokerageWithdrawMinPrice">
                    <el-input-number v-model="formData.brokerageWithdrawMinPrice" ></el-input-number>
                </el-form-item>
                <el-form-item label="用户提现次数" prop="brokerageWithdrawLimitNum">
                    <el-input-number v-model="formData.brokerageWithdrawLimitNum"></el-input-number>
                </el-form-item>

                <el-form-item label="用户提现手续费百分比" prop="brokerageWithdrawFeePercent">
                    <el-input-number v-model="formData.brokerageWithdrawFeePercent" :min="0" ></el-input-number>
                </el-form-item>
                <el-form-item label="活动预算金额" prop="brokerageBudgetPrice"> 
                    <el-input-number v-model="formData.brokerageBudgetPrice" ></el-input-number>
                </el-form-item>
                <el-form-item label="佣金冻结时间" prop="brokerageFrozenDays">
                    <el-input-number v-model="formData.brokerageFrozenDays" :min="0" ></el-input-number>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submit">保存</el-button>
                </el-form-item>
            </el-form>
        </el-card>
    </div>
</template>

<script>
import { getPayConfig, updatePayConfig } from '@/api/payConfig'
export default {

    data() {
        return {
            formData: {
                brokerageEnabled: true,
                brokerageEnabledCondition: 1,
                brokerageBindMode: 1,
                brokerageUserCondition: 1,
                brokerageWithdrawLimitNum: null,
                brokerageWithdrawTypes: [5],
                brokerageFrozenDays: null,
                brokerageWithdrawFeePercent: null,
                brokerageWithdrawMinPrice: null,
                brokerageBudgetPrice: null
            },
            formRuels: {
                brokerageWithdrawMinPrice: [
                    { required: true, message: "请输入用户提现最低金额", trigger: "blur" }
                ],
                brokerageWithdrawLimitNum: [
                    { required: true, message: "请输入用户提现次数", trigger: "blur" }
                ],
                brokerageWithdrawFeePercent: [
                    { required: true, message: "请输入用户提现手续费百分比", trigger: "blur" }
                ],
                brokerageFrozenDays: [
                    { required: true, message: "请输入佣金冻结时间", trigger: "blur" }
                ],
                brokerageBudgetPrice: [
                    { required: true, message: "请输入活动预算金额", trigger: "blur" }
                ]

            }
        }
    },
    created() {
       this.getInfo()
    },
    methods: {
        getInfo()  {
            getPayConfig().then(res => {
                if(res.data.brokerageWithdrawMinPrice > 0) {
                    res.data.brokerageWithdrawMinPrice = res.data.brokerageWithdrawMinPrice / 100
                    res.data.brokerageBudgetPrice = res.data.brokerageBudgetPrice / 100
                }
                this.formData = res.data
            })
        },
        submit() {
            this.$refs.formDataRef.validate(valid => {
                if (valid) {
                    let obj = Object.assign({}, this.formData);
                    obj.brokerageWithdrawMinPrice = obj.brokerageWithdrawMinPrice * 100
                    obj.brokerageBudgetPrice = obj.brokerageBudgetPrice * 100
                    updatePayConfig(obj).then(res=> {
                        this.$message.success('保存成功')
                        this.getInfo()
                    })
                }
            });
        }
    },
}
</script>

<style></style>